<template>
  <!-- 系统管理 -->
  <div class="app-container">
    <div class="mainbox">
      <!-- 顶部操作 -->
      <div class="filter-container">
        <el-form ref="filterFormRef" :inline="true" :model="filterForm">
          <el-form-item label="类型:" prop="resourceType">
            <el-select v-model.trim="filterForm.resourceType" placeholder="请选择" :clearable="true">
              <el-option
                v-for="dict in dict.type.XQZY"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="名称:" prop="title">
            <el-input
              v-model.trim="filterForm.title"
              class="filter-item limit"
              style="width: 200px;margin-right:10px"
              maxlength="30"
              clearable
              placeholder="请输入名称"
              @keyup.enter.native="$_handleFilter"
            />
          </el-form-item>
          <el-form-item label="地点:" prop="resourcePlace">
            <el-input
              v-model.trim="filterForm.resourcePlace"
              class="filter-item limit"
              style="width: 200px;margin-right:10px"
              maxlength="30"
              clearable
              placeholder="请输入地点"
              @keyup.enter.native="$_handleFilter"
            />
          </el-form-item>
        </el-form>
        <div class="flex-1" />
        <el-button type="primary" @click="$_handleFilter">查询</el-button>
        <el-button @click="$_handleReset">重置</el-button>

      </div>
      <!-- 表格 -->
      <div class="table-container table-fullscreen">
        <div class="table-opt-container">
          <el-button
            v-permission="['UR_PORTAL_XQZY_ADD_BUTTON']"
            type="primary"
            icon="el-icon-plus"
            @click="handleAdd"
          >
            新增
          </el-button>
          <el-button
            v-permission="['UR_PORTAL_XQZY_DOWNLOAD_BUTTON']"
            icon="el-icon-download"
            @click="handleExport('d')"
          >
            下载模板
          </el-button>
          <el-button
            v-permission="['UR_PORTAL_XQZY_IMPORT_BUTTON']"
            icon="el-icon-folder-add"
            type="primary"
            @click="$_handleImport()"
          >
            导入
          </el-button>
          <div class="flex-1" />
          <dt-dialog-column :columns="columns" @queryTable="getList" />
        </div>
        <el-table
          ref="table"
          v-loading="MX_listLoading"
          :data="MX_list"
          border
          highlight-current-row
          :row-key="$_getRowKey"
          style="width: 100%;text-align:center"
          :header-cell-style="MX_headerCellStyle"
        >
          <template slot="empty">
            <p>{{ $store.getters.dataText }}</p>
          </template>
          <el-table-column
            fixed="left"
            type="index"
            label="序号"
            width="70"
            align="center"
            :index="$_tableIndex"
          />
          <template v-for="item in columns">
            <el-table-column
              v-if="item.prop === 'image'"
              :key="item.prop"
              :prop="item.prop"
              :label="item.label"
              :width="item.width"
              :min-width="item.minWidth"
              align="center"
            >
              <template slot-scope="scope">
                <el-image style="width: 75px; height: 75px;" v-show="!!scope.row.image" :src="scope.row.image" :preview-src-list="[scope.row.image]" fit="contain"></el-image>
              </template>
            </el-table-column>
            <el-table-column
              v-else
              :key="item.prop"
              :prop="item.prop"
              :label="item.label"
              :width="item.width"
              :min-width="item.minWidth"
              :formatter="item.formatter"
              show-overflow-tooltip
              align="center"
            />
          </template>

          <el-table-column
            :key="Math.random()"
            fixed="right"
            label="操作"
            width="220px"
            align="center"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                class="tBtn"
                @click="$_handleDetail(scope.row)"
              >详情</el-button>
              <el-button
                v-permission="['UR_PORTAL_XQZY_UPDATE_BUTTON']"
                size="mini"
                class="tBtn"
                @click="handleEdit(scope.row)"
              >修改</el-button>
              <el-button
                v-permission="['UR_PORTAL_XQZY_DEL_BUTTON']"
                size="mini"
                type="danger"
                class="tBtn"
                @click="handleDelete(scope.row.resourceId)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <dt-pagination
          v-show="MX_total > 0"
          :total="MX_total"
          :page.sync="MX_pageNav.pageNo"
          :limit.sync="MX_pageNav.pageSize"
          @pagination="getList"
        />
      </div>
      <DialogForm ref="dialogForm" width="75%" labelWidth="65px" :formDesignList="formDesignList" />
      <dtDialog
        title="导入"
        class="get-page-form-import-dialog"
        :visible.sync="MX_fileUploadVisible"
        width="620px"
        :is-loading="MX_uploadLoading"
        @closeDialog="MX_fileUploadVisible = false"
        @comfirmBtn="$_importDataSave(importApi)"
      >
        <el-form slot="content">
          <div class="">
            <dt-importFile ref="dtImportFileRef" :down-load-template="handleImportTemplate" :type="fileName" />
          </div>
        </el-form>
      </dtDialog>
    </div>
  </div>
</template>

<script>
import unifiedReportingApi from '@/api/investment/unifiedReporting'
import DialogForm from '@/views/investment/components/DialogForm'
import commonList from "@/utils/mixins/investment/commonList";
import Template from "@/framework/views/messageCenter/template";

export default {
  name: 'JurisdictionalResources',
  components: {
    Template,
    DialogForm
  },
  dicts: ['XQZY'],
  mixins: [commonList],
  data() {
    return {
      filterForm: {
        resourceType: '',
        title: '',
        resourcePlace: '',
      },
      fileName: '辖区资源数据导入',
      handleImportTemplate: unifiedReportingApi.downloadXQZY,
      importApi: unifiedReportingApi.importXQZY,
      // 列信息
      columns: [
        { prop: 'resourceType', label: `类型`, width: '160px' },
        { prop: 'title', label: `名称` },
        // { prop: 'content', label: `描述` },
        { prop: 'resourcePlace', label: `地点`, width: '240px'  },
        { prop: 'image', label: `图片`, width: '115px' },
        { prop: 'sort', label: `排序`, width: '70px'  }
      ],
      formDesignList: [
        { type: 'select', prop: 'resourceTypeCode', label: `类型`, dictTypeCode: 'XQZY', rules: [{ required: true, message: '请输入类型', trigger: 'change' }] },
        { type: 'text', prop: 'title', label: `名称`, rules: [{ required: true, message: '请输入名称', trigger: 'blur' }] },
        { type: 'editor', prop: 'content', label: `描述`, rules: [{ required: true, message: '请输入描述', trigger: 'blur' }] },
        { type: 'text', prop: 'resourcePlace', label: `地点`, rules: [{ required: true, message: '请输入地点', trigger: 'blur' }] },
        { type: 'text', prop: 'resourcePlaceLon', label: `经度`, readonly: true, rules: [{ required: true, message: '请选择经度', trigger: 'blur' }] },
        { type: 'text', prop: 'resourcePlaceLat', label: `纬度`, readonly: true, rules: [{ required: true, message: '请选择纬度', trigger: 'blur' }] },
        { type: 'file', prop: 'image', label: `图片`, fileSize: 5, fileTypes: ['png', 'jpg', 'jpeg'], rules: [{ message: '请上传图片', trigger: 'change' }] },
        { type: 'number', prop: 'sort', label: `排序`, rules: [{ required: true, message: '请输入排序', trigger: 'blur' }] },
      ],
    }
  },
  created() {
    this.getList()
  },
  activated() {
  },
  methods: {
    // 获取页面列表
    getList() {
      this.$_getList(unifiedReportingApi.getXQZYList, {
        ...this.filterForm,
        ...this.MX_pageNav
      })
    },
    // 编辑按钮
    handleEdit(data) {
      this.$refs.dialogForm.open('update', unifiedReportingApi.updateXQZYItem, data || this.MX_applicationMsg)
    },
    // 添加按钮
    handleAdd() {
      this.$refs.dialogForm.open('add', unifiedReportingApi.addXQZYItem)
    },
    // 删除按钮
    handleDelete(id) {
      this.$_handleDelete(unifiedReportingApi.delXQZYItem, [id], 'resourceIds')
    },
    /** 下载按钮操作 */
    handleExport() {
      this.$_handleDownload(this.handleImportTemplate, `${this.fileName}模板`);
    },
  }
}
</script>

<style lang="scss" scoped>
.tBtn{
  margin-top: 3px;
  margin-bottom: 3px;
}
</style>
